package ui;
import java.awt.event.ActionEvent;
import java.sql.SQLException;
import java.util.Vector;

import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.LayoutStyle;
import javax.swing.ListModel;

import javax.swing.WindowConstants;
import javax.swing.border.BevelBorder;
import javax.swing.border.SoftBevelBorder;
import javax.swing.event.ListDataListener;
import javax.swing.SwingUtilities;
import dao.*;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class resultWindow extends javax.swing.JFrame {
	private boolean behavior = false;
	private BirdVO[] blist;
	private JPanel jPanel1;
	private JLabel jLabel3;
	private JLabel jLabel4;
	private JLabel jLabel5;
	private JScrollPane jScrollPane1;
	private JList resultList;
	private AbstractAction resultCloseAction;
	private JTextArea labelColor;
	private JTextArea resultClutch;
	private JButton updateButton;
	private JScrollPane jScrollPane9;
	private AbstractAction removeCountryAction;
	private AbstractAction addCountryAction;
	private JLabel labelCountry;
	private JButton removeCountry;
	private JButton addCountry;
	private JTextField countryText;
	private JList countryList;
	private JScrollPane jScrollPane8;
	private AbstractAction abstractAction1;
	private AbstractAction removePNAction;
	private AbstractAction addPNAction;
	private JTextField addField;
	private JButton addPopName;
	private JButton remove;
	private AbstractAction updateAction;
	private JScrollPane jScrollPane7;
	private JScrollPane jScrollPane5;
	private JScrollPane jScrollPane4;
	private JScrollPane jScrollPane3;
	private JComboBox resultRoF;
	private JTextArea resultLongevity;
	private JTextArea resultInc;
	private JTextArea resultSize;
	private JTextArea resultWeight;
	private JTextArea jTextArea1;
	private JScrollPane jScrollPane6;
	private JTextArea resultScientificNameLabel;
	private JTextArea labelURL;
	private JTextArea resultToF;
	private JScrollPane jScrollPane2;
	private JList popNameList;
	private JLabel jLabel15;
	private JLabel jLabel7;
	private JLabel jLabel12;
	private JLabel jLabel13;
	private JLabel jLabel14;
	private AbstractAction getFetch;
	private AbstractAction fetchAction;
	private JButton fetch;
	private JLabel jLabel11;
	private JLabel jLabel10;
	private JLabel jLabel9;
	private JLabel jLabel8;
	private JLabel jLabel6;
	private JLabel jLabel2;
	private JLabel jLabel1;
	private Vector<String> popName;
	private Vector<String> countryListOMG;
	private int displaying = 0;

	public resultWindow() {
		super();
		initGUI();
		popName = new Vector<String>();
		countryListOMG = new Vector<String>();
	}
	
	public void setSearchBehavior() {
		updateButton.setEnabled(false);
		updateButton.setVisible(false);
		popNameList.setEnabled(false);
		addField.setEditable(false);
		addPNAction.setEnabled(false);
		removePNAction.setEnabled(false);
		addCountry.setEnabled(false);
		countryText.setEditable(false);
		removeCountry.setEnabled(false);
	}
	
	public void setUpdateBehavior() {
		behavior = true;
		resultWeight.setEditable(true);
		resultRoF.setEnabled(true);
		resultToF.setEditable(true);
		jTextArea1.setEditable(true);
		resultSize.setEditable(true);
		resultInc.setEditable(true);
		resultLongevity.setEditable(true);
		resultClutch.setEditable(true);
		labelColor.setEditable(true);
		labelURL.setEditable(true);
	}
	
	private void initGUI() {
		
		try {
			GroupLayout thisLayout = new GroupLayout((JComponent)getContentPane());
			getContentPane().setLayout(thisLayout);
			thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
				.addComponent(getJScrollPane2(), 0, 485, Short.MAX_VALUE));
			thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup()
				.addComponent(getJScrollPane2(), 0, 567, Short.MAX_VALUE));
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			this.setTitle("Search Results");
			pack();
			this.setSize(565, 506);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	private AbstractAction getResultCloseAction() {
		if(resultCloseAction == null) {
			resultCloseAction = new AbstractAction("Close", null) {
				public void actionPerformed(ActionEvent evt) {
					setVisible(false);
			        dispose();
				}
			};
		}
		return resultCloseAction;
	}
	
	private JList getResultList() {
		Vector<String> birdNames = new Vector<String>();
		
		if(resultList == null) {
			ListModel resultListModel = 
				new DefaultComboBoxModel(
					birdNames.toArray());
			resultList = new JList();
			resultList.setModel(resultListModel);
		}
		return resultList;
	}
	
	private JScrollPane getJScrollPane1() {
		if(jScrollPane1 == null) {
			jScrollPane1 = new JScrollPane();
			jScrollPane1.setViewportView(getResultList());
		}
		return jScrollPane1;
	}
	
	private JButton getFetch() {
		if(fetch == null) {
			fetch = new JButton();
			fetch.setText("Display");
			fetch.setAction(getGetFetch());
		}
		return fetch;
	}
	
	//Locally stores the birds which the search engine found.
	public void insertData(BirdVO[] data) {
		Vector<String> birdNames = new Vector<String>();
		ListModel lM;
		blist = data;
		
		birdNames.add("None");
		if (blist!= null && blist.length > 0) {
			for (int i = 0; i < blist.length; i++ ) {
				birdNames.add(blist[i].getScientific_name());
			}
		}
		
		lM = new DefaultComboBoxModel(birdNames.toArray());
		
		resultList.setModel(lM);
	}
	
	private AbstractAction getGetFetch() {
		if(getFetch == null) {
			getFetch = new AbstractAction("Display Info", null) {
				public void actionPerformed(ActionEvent evt) {
					displaying = resultList.getSelectedIndex();
					int index = displaying;
					String food,sciName, size,
					weight, habitat, roe,incub, longevity, clutch, color,
					imgurl;
					int i = 0;
					ComboBoxModel cM = new DefaultComboBoxModel(mainWindow.RiskOfExtinction);
					getResultRoF().setModel(cM);
					popName.clear();
					
					if ( index > 0 && blist.length > 0 ) {
						/* GetInfo */
						food = blist[index-1].getDiet();
						roe = blist[index-1].getRisk_of_extinction();
						sciName = blist[index-1].getScientific_name();
						size = String.valueOf(blist[index-1].getSize());
						weight = String.valueOf(blist[index-1].getWeight());
						habitat = blist[index-1].getHabitat();
						incub = String.valueOf(blist[index-1].getIncubationtime());
						longevity = String.valueOf(blist[index-1].getLongevity());
						clutch = String.valueOf(blist[index-1].getClutchsize());
						color = blist[index-1].getColor();
						imgurl = blist[index-1].getImageurl();

						/* Print stuff */
						resultScientificNameLabel.setText(sciName);
						Vector<String> dum = new Vector<String>();
						Vector<String> dum2 = new Vector<String>();
						
						try {
							for(PopularNamesVO ovo: BirdDAO.listPopularNames(blist[index-1])) {
								dum.add(ovo.getName());
								popName.add(ovo.getName());
							}
							for(CountryVO ovo: CountryDAO.selectByBird_scientific_name(sciName)) {
								dum2.add(ovo.getCountry());
								countryListOMG.add(ovo.getCountry());
							}
						} catch (SQLException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						
						addPopularNamesToList(dum);
						addCountriesToList(dum2);
						resultWeight.setText(weight);
						
						for(i = 0; i < mainWindow.RiskOfExtinction.length; i++) {
							if (mainWindow.RiskOfExtinction[i].equals(roe)) {
								break;
							}
						}
						
						resultRoF.setSelectedIndex(i);
						resultToF.setText(food);
						jTextArea1.setText(habitat);
						resultSize.setText(size);
						resultInc.setText(incub);
						resultLongevity.setText(longevity);
						resultClutch.setText(clutch);
						labelColor.setText(color);
						labelURL.setText(imgurl);
					} else {
						resultScientificNameLabel.setText("none");
						resultWeight.setText("none");
						resultRoF.setModel(new DefaultComboBoxModel(new String[] { "none" }));
						resultToF.setText("none");
						jTextArea1.setText("none");
						resultSize.setText("none");
						resultInc.setText("none");
						resultLongevity.setText("none");
						resultClutch.setText("none");
						labelColor.setText("none");
						labelURL.setText("none");
					}
				}
			};
		}
		return getFetch;
	}
	
	private JLabel getJLabel14() {
		if(jLabel14 == null) {
			jLabel14 = new JLabel();
			jLabel14.setText("Color:");
		}
		return jLabel14;
	}
	
	private JLabel getJLabel13() {
		if(jLabel13 == null) {
			jLabel13 = new JLabel();
			jLabel13.setText("Image URL:");
		}
		return jLabel13;
	}
	
	private JLabel getJLabel12() {
		if(jLabel12 == null) {
			jLabel12 = new JLabel();
			jLabel12.setText("Clutch Size (eggs):");
		}
		return jLabel12;
	}
	
	private JLabel getJLabel7() {
		if(jLabel7 == null) {
			jLabel7 = new JLabel();
			jLabel7.setText("Longevity (years):");
		}
		return jLabel7;
	}
	
	private JLabel getJLabel15() {
		if(jLabel15 == null) {
			jLabel15 = new JLabel();
			jLabel15.setText("Incubation Time (days):");
		}
		return jLabel15;
	}

	private JList getPopNameList() {
		if(popNameList == null) {
			ListModel popNameListModel = 
				new DefaultComboBoxModel(
						new String[] { "" });
			popNameList = new JList();
			popNameList.setModel(popNameListModel);
		}
		return popNameList;
	}
	
	private void addPopularNamesToList(Vector<String> names) {
		ListModel popNameListModel = new DefaultComboBoxModel(names);
		popNameList.setModel(popNameListModel);
	}
	
	private void addCountriesToList(Vector<String> ct) {
		ListModel countrylist = new DefaultComboBoxModel(ct);
		countryList.setModel(countrylist);
	}
	
	private JScrollPane getJScrollPane2() {
		if(jScrollPane2 == null) {
			jScrollPane2 = new JScrollPane();
			jScrollPane2.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
			{
				jPanel1 = new JPanel();
				jScrollPane2.setViewportView(jPanel1);
				GroupLayout jPanel1Layout = new GroupLayout((JComponent)jPanel1);
				jPanel1.setLayout(jPanel1Layout);
				jPanel1.setPreferredSize(new java.awt.Dimension(535, 740));
				jPanel1.setSize(535, 600);
				{
					jLabel1 = new JLabel();
					jLabel1.setText("General Information");
				}
				{
					jLabel2 = new JLabel();
					jLabel2.setText("Scientific Name:");
				}
				{
					jLabel3 = new JLabel();
					jLabel3.setText("Popular Name:");
				}
				{
					jLabel4 = new JLabel();
					jLabel4.setText("Weight (g):");
				}
				{
					jLabel5 = new JLabel();
					jLabel5.setText("Size (cm):");
				}
				{
					jLabel6 = new JLabel();
					jLabel6.setText("Risk of Extintion:");
				}
				{
					jLabel8 = new JLabel();
					jLabel8.setText("Food Information");
				}
				{
					jLabel9 = new JLabel();
					jLabel9.setText("Feeds on:");
				}
				{
					jLabel10 = new JLabel();
					jLabel10.setText("Habitat Information");
				}
				{
					jLabel11 = new JLabel();
					jLabel11.setText("Habitat:");
				}
				jPanel1Layout.setHorizontalGroup(jPanel1Layout.createSequentialGroup()
					.addContainerGap()
					.addGroup(jPanel1Layout.createParallelGroup()
					    .addComponent(getJScrollPane1(), GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 130, GroupLayout.PREFERRED_SIZE)
					    .addComponent(getFetch(), GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 130, GroupLayout.PREFERRED_SIZE)
					    .addComponent(getUpdateButton(), GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 130, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					.addGroup(jPanel1Layout.createParallelGroup()
					    .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
					        .addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, 149, GroupLayout.PREFERRED_SIZE)
					        .addGap(16))
					    .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
					        .addComponent(jLabel8, GroupLayout.PREFERRED_SIZE, 104, GroupLayout.PREFERRED_SIZE)
					        .addGap(61))
					    .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
					        .addComponent(jLabel10, GroupLayout.PREFERRED_SIZE, 149, GroupLayout.PREFERRED_SIZE)
					        .addGap(16))
					    .addGroup(jPanel1Layout.createSequentialGroup()
					        .addPreferredGap(jLabel1, getLabelCountry(), LayoutStyle.ComponentPlacement.INDENT)
					        .addGroup(jPanel1Layout.createParallelGroup()
					            .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
					                .addComponent(getLabelCountry(), GroupLayout.PREFERRED_SIZE, 128, GroupLayout.PREFERRED_SIZE)
					                .addGap(25))
					            .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
					                .addComponent(jLabel11, GroupLayout.PREFERRED_SIZE, 116, GroupLayout.PREFERRED_SIZE)
					                .addGap(37))
					            .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
					                .addComponent(jLabel9, GroupLayout.PREFERRED_SIZE, 128, GroupLayout.PREFERRED_SIZE)
					                .addGap(25))
					            .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
					                .addComponent(getJLabel14(), GroupLayout.PREFERRED_SIZE, 123, GroupLayout.PREFERRED_SIZE)
					                .addGap(30))
					            .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
					                .addComponent(getJLabel13(), GroupLayout.PREFERRED_SIZE, 116, GroupLayout.PREFERRED_SIZE)
					                .addGap(37))
					            .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
					                .addComponent(getJLabel12(), GroupLayout.PREFERRED_SIZE, 132, GroupLayout.PREFERRED_SIZE)
					                .addGap(21))
					            .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
					                .addComponent(getJLabel7(), GroupLayout.PREFERRED_SIZE, 104, GroupLayout.PREFERRED_SIZE)
					                .addGap(49))
					            .addComponent(getJLabel15(), GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 153, GroupLayout.PREFERRED_SIZE)
					            .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
					                .addComponent(jLabel6, GroupLayout.PREFERRED_SIZE, 116, GroupLayout.PREFERRED_SIZE)
					                .addGap(37))
					            .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
					                .addComponent(jLabel5, GroupLayout.PREFERRED_SIZE, 116, GroupLayout.PREFERRED_SIZE)
					                .addGap(37))
					            .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
					                .addComponent(jLabel4, GroupLayout.PREFERRED_SIZE, 116, GroupLayout.PREFERRED_SIZE)
					                .addGap(37))
					            .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
					                .addComponent(jLabel3, GroupLayout.PREFERRED_SIZE, 116, GroupLayout.PREFERRED_SIZE)
					                .addGap(37))
					            .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
					                .addComponent(jLabel2, GroupLayout.PREFERRED_SIZE, 116, GroupLayout.PREFERRED_SIZE)
					                .addGap(37)))))
					.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
					.addGroup(jPanel1Layout.createParallelGroup()
					    .addGroup(jPanel1Layout.createSequentialGroup()
					        .addComponent(getJScrollPane9(), GroupLayout.PREFERRED_SIZE, 179, GroupLayout.PREFERRED_SIZE))
					    .addGroup(jPanel1Layout.createSequentialGroup()
					        .addComponent(getJScrollPane7(), GroupLayout.PREFERRED_SIZE, 179, GroupLayout.PREFERRED_SIZE))
					    .addGroup(jPanel1Layout.createSequentialGroup()
					        .addComponent(getJScrollPane5(), GroupLayout.PREFERRED_SIZE, 179, GroupLayout.PREFERRED_SIZE))
					    .addGroup(jPanel1Layout.createSequentialGroup()
					        .addComponent(getJScrollPane4(), GroupLayout.PREFERRED_SIZE, 179, GroupLayout.PREFERRED_SIZE))
					    .addGroup(jPanel1Layout.createSequentialGroup()
					        .addComponent(getJScrollPane3(), GroupLayout.PREFERRED_SIZE, 179, GroupLayout.PREFERRED_SIZE))
					    .addGroup(jPanel1Layout.createSequentialGroup()
					        .addComponent(getResultClutch(), GroupLayout.PREFERRED_SIZE, 179, GroupLayout.PREFERRED_SIZE))
					    .addGroup(jPanel1Layout.createSequentialGroup()
					        .addComponent(getResultLongevity(), GroupLayout.PREFERRED_SIZE, 179, GroupLayout.PREFERRED_SIZE))
					    .addGroup(jPanel1Layout.createSequentialGroup()
					        .addComponent(getResultInc(), GroupLayout.PREFERRED_SIZE, 179, GroupLayout.PREFERRED_SIZE))
					    .addGroup(jPanel1Layout.createSequentialGroup()
					        .addComponent(getResultRoF(), GroupLayout.PREFERRED_SIZE, 179, GroupLayout.PREFERRED_SIZE))
					    .addGroup(jPanel1Layout.createSequentialGroup()
					        .addComponent(getResultSize(), GroupLayout.PREFERRED_SIZE, 179, GroupLayout.PREFERRED_SIZE))
					    .addGroup(jPanel1Layout.createSequentialGroup()
					        .addComponent(getResultWeight(), GroupLayout.PREFERRED_SIZE, 179, GroupLayout.PREFERRED_SIZE))
					    .addGroup(jPanel1Layout.createSequentialGroup()
					        .addComponent(getJScrollPane8(), GroupLayout.PREFERRED_SIZE, 179, GroupLayout.PREFERRED_SIZE))
					    .addGroup(jPanel1Layout.createSequentialGroup()
					        .addComponent(getJScrollPane6(), GroupLayout.PREFERRED_SIZE, 179, GroupLayout.PREFERRED_SIZE))
					    .addGroup(jPanel1Layout.createSequentialGroup()
					        .addComponent(getAddField(), GroupLayout.PREFERRED_SIZE, 179, GroupLayout.PREFERRED_SIZE))
					    .addGroup(jPanel1Layout.createSequentialGroup()
					        .addComponent(getAddPopName(), GroupLayout.PREFERRED_SIZE, 179, GroupLayout.PREFERRED_SIZE))
					    .addGroup(jPanel1Layout.createSequentialGroup()
					        .addComponent(getRemove(), GroupLayout.PREFERRED_SIZE, 179, GroupLayout.PREFERRED_SIZE))
					    .addGroup(jPanel1Layout.createSequentialGroup()
					        .addComponent(getCountryText(), GroupLayout.PREFERRED_SIZE, 179, GroupLayout.PREFERRED_SIZE))
					    .addGroup(jPanel1Layout.createSequentialGroup()
					        .addComponent(getAddCountry(), GroupLayout.PREFERRED_SIZE, 179, GroupLayout.PREFERRED_SIZE))
					    .addGroup(jPanel1Layout.createSequentialGroup()
					        .addComponent(getRemoveCountry(), GroupLayout.PREFERRED_SIZE, 179, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap(19, Short.MAX_VALUE));
				jPanel1Layout.setVerticalGroup(jPanel1Layout.createSequentialGroup()
					.addContainerGap()
					.addGroup(jPanel1Layout.createParallelGroup()
					    .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
					        .addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					        .addGroup(jPanel1Layout.createParallelGroup()
					            .addComponent(getJScrollPane6(), GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE)
					            .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
					                .addComponent(jLabel2, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					                .addGap(7)))
					        .addGroup(jPanel1Layout.createParallelGroup()
					            .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
					                .addComponent(jLabel3, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					                .addGap(33))
					            .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
					                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					                .addComponent(getJScrollPane8(), GroupLayout.PREFERRED_SIZE, 43, GroupLayout.PREFERRED_SIZE)))
					        .addComponent(getAddField(), GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					        .addComponent(getAddPopName(), GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					        .addComponent(getRemove(), GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					        .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
					        .addGroup(jPanel1Layout.createParallelGroup()
					            .addComponent(getResultWeight(), GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE)
					            .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
					                .addComponent(jLabel4, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					                .addGap(10)))
					        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					        .addGroup(jPanel1Layout.createParallelGroup()
					            .addComponent(getResultSize(), GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE)
					            .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
					                .addComponent(jLabel5, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					                .addGap(8)))
					        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					        .addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
					            .addComponent(getResultRoF(), GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					            .addComponent(jLabel6, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
					        .addGap(6))
					    .addComponent(getJScrollPane1(), GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 276, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					.addComponent(getFetch(), GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					.addGroup(jPanel1Layout.createParallelGroup()
					    .addGroup(jPanel1Layout.createSequentialGroup()
					        .addGroup(jPanel1Layout.createParallelGroup()
					            .addComponent(getResultInc(), GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE)
					            .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
					                .addComponent(getJLabel15(), GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					                .addGap(8)))
					        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					        .addGroup(jPanel1Layout.createParallelGroup()
					            .addComponent(getResultLongevity(), GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE)
					            .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
					                .addComponent(getJLabel7(), GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					                .addGap(8))))
					    .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
					        .addGap(11)
					        .addComponent(getUpdateButton(), GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE)
					        .addGap(20)))
					.addGroup(jPanel1Layout.createParallelGroup()
					    .addComponent(getResultClutch(), GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE)
					    .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
					        .addComponent(getJLabel12(), GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
					        .addGap(11)))
					.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					.addGroup(jPanel1Layout.createParallelGroup()
					    .addComponent(getJScrollPane3(), GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)
					    .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
					        .addComponent(getJLabel13(), GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					        .addGap(14)))
					.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					.addGroup(jPanel1Layout.createParallelGroup()
					    .addComponent(getJScrollPane4(), GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 32, GroupLayout.PREFERRED_SIZE)
					    .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
					        .addComponent(getJLabel14(), GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					        .addGap(16)))
					.addComponent(jLabel8, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					.addGroup(jPanel1Layout.createParallelGroup()
					    .addComponent(getJScrollPane5(), GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)
					    .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
					        .addComponent(jLabel9, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					        .addGap(14)))
					.addComponent(jLabel10, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					.addGroup(jPanel1Layout.createParallelGroup()
					    .addComponent(getJScrollPane7(), GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 27, GroupLayout.PREFERRED_SIZE)
					    .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
					        .addComponent(jLabel11, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					        .addGap(11)))
					.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
					.addGroup(jPanel1Layout.createParallelGroup()
					    .addComponent(getJScrollPane9(), GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 48, GroupLayout.PREFERRED_SIZE)
					    .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
					        .addComponent(getLabelCountry(), GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					        .addGap(32)))
					.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					.addComponent(getCountryText(), GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					.addComponent(getAddCountry(), GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					.addComponent(getRemoveCountry(), GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(28, Short.MAX_VALUE));
			}
		}
		return jScrollPane2;
	}
	
	private JTextArea getResultToF() {
		if(resultToF == null) {
			resultToF = new JTextArea();
			resultToF.setEditable(false);
			resultToF.setDisabledTextColor(new java.awt.Color(0,0,0));
			resultToF.setLineWrap(true);
		}
		return resultToF;
	}
	
	private JTextArea getLabelURL() {
		if(labelURL == null) {
			labelURL = new JTextArea();
			labelURL.setEditable(false);
			labelURL.setDisabledTextColor(new java.awt.Color(0,0,0));
			labelURL.setRequestFocusEnabled(false);
			labelURL.setLineWrap(true);
		}
		return labelURL;
	}
	
	private JTextArea getLabelColor() {
		if(labelColor == null) {
			labelColor = new JTextArea();
			labelColor.setEditable(false);
			labelColor.setLineWrap(true);
		}
		return labelColor;
	}

	private JTextArea getResultScientificNameLabel() {
		if(resultScientificNameLabel == null) {
			resultScientificNameLabel = new JTextArea();
			resultScientificNameLabel.setDisabledTextColor(new java.awt.Color(0,0,0));
			resultScientificNameLabel.setLineWrap(true);
			resultScientificNameLabel.setEditable(false);
		}
		return resultScientificNameLabel;
	}
	
	private JScrollPane getJScrollPane6() {
		if(jScrollPane6 == null) {
			jScrollPane6 = new JScrollPane();
			jScrollPane6.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
			jScrollPane6.setViewportView(getResultScientificNameLabel());
		}
		return jScrollPane6;
	}
	
	private JTextArea getJTextArea1() {
		if(jTextArea1 == null) {
			jTextArea1 = new JTextArea();
			jTextArea1.setLineWrap(true);
			jTextArea1.setDisabledTextColor(new java.awt.Color(0,0,0));
			jTextArea1.setEditable(false);
		}
		return jTextArea1;
	}

	private JTextArea getResultWeight() {
		if(resultWeight == null) {
			resultWeight = new JTextArea();
			resultWeight.setBorder(BorderFactory.createTitledBorder(""));
			resultWeight.setEditable(false);
		}
		return resultWeight;
	}
	
	private JTextArea getResultSize() {
		if(resultSize == null) {
			resultSize = new JTextArea();
			resultSize.setBorder(BorderFactory.createTitledBorder(""));
			resultSize.setEditable(false);
		}
		return resultSize;
	}

	private JTextArea getResultInc() {
		if(resultInc == null) {
			resultInc = new JTextArea();
			resultInc.setBorder(BorderFactory.createTitledBorder(""));
			resultInc.setEditable(false);
		}
		return resultInc;
	}
	
	private JTextArea getResultLongevity() {
		if(resultLongevity == null) {
			resultLongevity = new JTextArea();
			resultLongevity.setBorder(BorderFactory.createTitledBorder(""));
			resultLongevity.setEditable(false);
		}
		return resultLongevity;
	}
	
	private JTextArea getResultClutch() {
		if(resultClutch == null) {
			resultClutch = new JTextArea();
			resultClutch.setBorder(BorderFactory.createTitledBorder(""));
			resultClutch.setEditable(false);
		}
		return resultClutch;
	}

	private JComboBox getResultRoF() {
		if(resultRoF == null) {
			ComboBoxModel resultRoFModel = 
				new DefaultComboBoxModel(
						mainWindow.RiskOfExtinction);
			resultRoF = new JComboBox();
			resultRoF.setModel(resultRoFModel);
			resultRoF.setEnabled(false);
		}
		return resultRoF;
	}

	private JScrollPane getJScrollPane3() {
		if(jScrollPane3 == null) {
			jScrollPane3 = new JScrollPane();
			jScrollPane3.setViewportView(getLabelURL());
		}
		return jScrollPane3;
	}
	
	private JScrollPane getJScrollPane4() {
		if(jScrollPane4 == null) {
			jScrollPane4 = new JScrollPane();
			jScrollPane4.setViewportView(getLabelColor());
		}
		return jScrollPane4;
	}
	
	private JScrollPane getJScrollPane5() {
		if(jScrollPane5 == null) {
			jScrollPane5 = new JScrollPane();
			jScrollPane5.setViewportView(getResultToF());
		}
		return jScrollPane5;
	}
	
	private JScrollPane getJScrollPane7() {
		if(jScrollPane7 == null) {
			jScrollPane7 = new JScrollPane();
			jScrollPane7.setViewportView(getJTextArea1());
		}
		return jScrollPane7;
	}

	private void Update() {
		String txt;
		String roe;
		float size = 0;
		float weight = 0;
		successDialog sD = new successDialog(resultWindow.this);
		
		try {
			txt = "Successfuly Updated!";
			BirdVO b = new BirdVO(getResultScientificNameLabel().getText(),
					(String)getResultRoF().getSelectedItem(),
					getLabelURL().getText(),
					Float.valueOf(getResultWeight().getText()),
					getJTextArea1().getText(),
					Float.valueOf(getResultInc().getText()),
					Float.valueOf(getResultLongevity().getText()),
					getLabelColor().getText(),
					Float.valueOf(getResultSize().getText()),
					Float.valueOf(getResultClutch().getText()),
					getResultToF().getText()
					);
			BirdDAO.writeBird(b);
			for ( String s : popName )
				BirdDAO.addPopularName(s, b);
			for ( String s : countryListOMG)
				BirdDAO.addCountry(s, b);
		} catch (SQLException ex) 
		{
			txt = "Update Failed!";
			
			System.out.println(ex.getMessage());
		} catch (Exception e) {

			txt = "Invalid information.";
		}
		
		sD.setLabelText(txt);
		sD.pack();
		sD.setLocationRelativeTo(null);
		sD.setVisible(true);										
	}
	
	private AbstractAction getUpdateAction() {
		if(updateAction == null) {
			updateAction = new AbstractAction("Update", null) {
				public void actionPerformed(ActionEvent evt) {
					if (displaying > 0) {
						Update();
						insertData(blist);
					}
				}
			};
		}
		return updateAction;
	}
	
	private JButton getRemove() {
		if(remove == null) {
			remove = new JButton();
			remove.setEnabled(true);
			remove.setText("Remove Popular Name");
			remove.setAction(getRemovePNAction());
			remove.setVisible(true);
			//remove.setAction(getRemovePNAction());
		}
		return remove;
	}
	
	private JButton getAddPopName() {
		if(addPopName == null) {
			addPopName = new JButton();
			addPopName.setEnabled(true);
			addPopName.setText("Add Popular Name");
			addPopName.setAction(getAddPNAction());
			addPopName.setVisible(true);
		//	addPopName.setAction(getAddPNAction());
		}
		return addPopName;
	}
	
	private JTextField getAddField() {
		if(addField == null) {
			addField = new JTextField();
			addField.setVisible(true);
			addField.setEnabled(true);
		}
		return addField;
	}
	
	private AbstractAction getAddPNAction() {
		if(addPNAction == null) {
			addPNAction = new AbstractAction("Add Popular Name", null) {
				public void actionPerformed(ActionEvent evt) {
					if (getAddField().getText().length() > 0) {
						popName.add(getAddField().getText());
						ListModel lM = new DefaultComboBoxModel(popName);
						getPopNameList().setModel(lM);
					}
				}
			};
		}
		return addPNAction;
	}
	
	private AbstractAction getRemovePNAction() {
		if(removePNAction == null) {
			removePNAction = new AbstractAction("Remove Popular Name", null) {
				public void actionPerformed(ActionEvent evt) {
					if ( getAddField().getText().length() > 0 )
						RemovePopularNameFromList(getAddField().getText());
				}
			};
		}
		return removePNAction;
	}

	private void RemovePopularNameFromList(String str) {
		ListModel lM;
		popName.remove(str);
		BirdVO b = new BirdVO();
		b.setScientific_name(resultScientificNameLabel.getText());
		try {
			BirdDAO.removePopularName(str, b);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		lM = new DefaultComboBoxModel(popName);
		popNameList.setModel(lM);
	}
	
	private void RemoveCountryFromList(String str) {
		ListModel lM;
		countryListOMG.remove(str);
		BirdVO b = new BirdVO();
		b.setScientific_name(resultScientificNameLabel.getText());
		try {
			BirdDAO.removeCountry(str, b);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		lM = new DefaultComboBoxModel(countryListOMG);
		countryList.setModel(lM);
	}
	
	private JScrollPane getJScrollPane8() {
		if(jScrollPane8 == null) {
			jScrollPane8 = new JScrollPane();
			jScrollPane8.setViewportView(getPopNameList());
		}
		return jScrollPane8;
	}

	private JList getCountryList() {
		if(countryList == null) {
			ListModel countryListModel = 
				new DefaultComboBoxModel(
						new String[] { "" });
			countryList = new JList();
			countryList.setModel(countryListModel);
		}
		return countryList;
	}
	
	private JTextField getCountryText() {
		if(countryText == null) {
			countryText = new JTextField();
		}
		return countryText;
	}
	
	private JButton getAddCountry() {
		if(addCountry == null) {
			addCountry = new JButton();
			addCountry.setText("Add Country");
			addCountry.setAction(getAddCountryAction());
		}
		return addCountry;
	}
	
	private JButton getRemoveCountry() {
		if(removeCountry == null) {
			removeCountry = new JButton();
			removeCountry.setText("Remove Country");
			removeCountry.setAction(getRemoveCountryAction());
		}
		return removeCountry;
	}
	
	private JLabel getLabelCountry() {
		if(labelCountry == null) {
			labelCountry = new JLabel();
			labelCountry.setText("Country:");
		}
		return labelCountry;
	}
	
	private AbstractAction getAddCountryAction() {
		if(addCountryAction == null) {
			addCountryAction = new AbstractAction("Add Country", null) {
				public void actionPerformed(ActionEvent evt) {
					if (getCountryText().getText().length() > 0) {
						countryListOMG.add(getCountryText().getText());
						ListModel lM = new DefaultComboBoxModel(countryListOMG);
						getCountryList().setModel(lM);
					}
				}
			};
		}
		return addCountryAction;
	}
	
	private AbstractAction getRemoveCountryAction() {
		if(removeCountryAction == null) {
			removeCountryAction = new AbstractAction("Remove Country", null) {
				public void actionPerformed(ActionEvent evt) {
					if ( getCountryText().getText().length() > 0 )
						RemoveCountryFromList(getCountryText().getText());
				}
			};
		}
		return removeCountryAction;
	}
	
	private JScrollPane getJScrollPane9() {
		if(jScrollPane9 == null) {
			jScrollPane9 = new JScrollPane();
			jScrollPane9.setViewportView(getCountryList());
		}
		return jScrollPane9;
	}
	
	private JButton getUpdateButton() {
		if(updateButton == null) {
			updateButton = new JButton();
			updateButton.setText("Update");
			updateButton.setAction(getUpdateAction());
		}
		return updateButton;
	}

}
